import os
import pygame
from random import *


# 获取当前项目的路径
projectPath=os.path.abspath('..')

# 提供超级子弹的补给
class BulletSupply(pygame.sprite.Sprite):
    def __init__(self,bg_size):
        pygame.sprite.Sprite.__init__(self)

        self.width = bg_size[0]
        self.height = bg_size[1]
        self.image = pygame.image.load(projectPath + "/resources/images/bullet_supply.png").convert_alpha()
        self.rect = self.image.get_rect()
        self.rect.left = randint(0, (self.width - self.rect.width))
        self.rect.bottom = -100

        self.speed = 3
        self.active = False
        self.mask = pygame.mask.from_surface(self.image)

    # 定义移动的方法
    def move(self):
        if self.rect.top < self.height:
            self.rect.top += self.speed
        else:
            self.active=False

    def reset(self):
        self.active = True
        self.rect.left = randint(0, (self.width - self.rect.width))
        self.rect.bottom = -100


# 提供炸弹的补给
class BombSupply(pygame.sprite.Sprite):
    def __init__(self,bg_size):
        pygame.sprite.Sprite.__init__(self)

        self.width = bg_size[0]
        self.height = bg_size[1]
        self.image = pygame.image.load(projectPath + "/resources/images/bomb_supply.png").convert_alpha()
        self.rect = self.image.get_rect()
        self.rect.left = randint(0, (self.width - self.rect.width))
        self.rect.bottom = -100

        self.speed = 3
        self.active = False
        self.mask = pygame.mask.from_surface(self.image)

    # 定义移动的方法
    def move(self):
        if self.rect.top < self.height:
            self.rect.top += self.speed
        else:
            self.active = False

    def reset(self):
        self.active = True
        self.rect.left = randint(0, (self.width - self.rect.width))
        self.rect.bottom = -100